package rr.sb.getContent.parsers;

public class BancuriEpistoleRoParser extends ContentParser {

    boolean step1, step2;

    String step1Marker = "<!-- article-content -->";
    String step2Marker = "<p";
    String step3Marker = "</p>";

    boolean titleStep1, titleStep2;
    String title1Marker = "<h2 class=\"art-postheader\">";
    String title2Marker = "rel=\"bookmark\"";
    String title3Marker = "</a>";

    boolean categoryStep1;
    String category1marker = "Posted in <a href";
    String category2marker = "rel=\"category tag\">";
    String category3marker = "</a>";

    @Override
    public void processLine(String currentLine) {

	if (currentLine.contains(title1Marker)) {
	    titleStep1 = true;
	}
	if (titleStep1 && currentLine.contains(title2Marker)) {
	    titleStep2 = true;
	}
	if (titleStep2 && currentLine.contains(title3Marker)) {
	    contentTitle = currentLine.substring(0, currentLine.length() - title3Marker.length());
	    titleStep1 = false;
	    titleStep2 = false;
	}

	if (contentTitle != null) {
	    if (currentLine.startsWith(step1Marker)) {
		step1 = true;
	    }

	    if (step1 && currentLine.startsWith(step2Marker)) {
		step2 = true;
		if (currentLine.endsWith(step3Marker)) {
		    addContentLine(currentLine.substring(currentLine.indexOf(">") + 1, currentLine.length() - step3Marker.length()));
		    step1 = false;
		    step2 = false;
		} else {
		    addContentLine(currentLine.substring(currentLine.indexOf(">") + 1));
		}
		return;
	    }

	    if (step2 && currentLine.endsWith(step3Marker)) {
		addContentLine(currentLine.substring(0, currentLine.length() - step3Marker.length()));
		step1 = false;
		step2 = false;
		return;
	    }

	    if (step2) {
		addContentLine(currentLine);
		return;
	    }
	}

	if (currentLine.startsWith(category1marker) && currentLine.contains(category2marker) && currentLine.contains(category3marker)) {
	    contentCategory = currentLine.substring(currentLine.indexOf(category2marker) + category2marker.length(),
		    currentLine.indexOf(category3marker));
	    addContent();
	}
    }

}
